package com.zyyfw;


import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;
import java.util.HashMap;
import java.util.Map;


@Configuration
public class CxfConfig {

    @Bean
    public ServletRegistrationBean dispatcherServlet() {
        CXFServlet cxfServlet = new CXFServlet();
        cxfServlet.setBus(springBus());
        return new ServletRegistrationBean(cxfServlet, "/soap/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        SpringBus springBus = new SpringBus();
        springBus.setProperty("org.apache.cxf.stax.maxTextLength", 268435456);//限制文件大小
        return springBus;
    }

    @Bean
    public FileWS FileWS() {
        return new FileWSImpl();
    }

    //此处要注意导入正取的Endpoint、EndpointImpl包
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), FileWS());
        endpoint.publish("/user");
        Map<String,Object> ps = new HashMap<>();
        ps.put("mtom_enabled",true);
        endpoint.setProperties(ps);
        return endpoint;
    }
}
